package com.zkingsoft.wechat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.web.BaseAction;
import com.zkingsoft.bean.BizAuth;
import com.zkingsoft.bean.BizUser;
import com.zkingsoft.common.constance.AppConstance;
import com.zkingsoft.dao.BizAuthDao;
import com.zkingsoft.dao.DataDictionaryDao;
import com.zkingsoft.redis.RedisUserLoginUtils;

/**
 * @description 会员相关接口
 * @author 姜友瑶
 * @date 2018-05-23 00:08
 */
@Controller
@RequestMapping(value = "wxapi/auth")
public class AuthAction extends BaseAction {

	@Autowired
	private BizAuthDao authDao;

	@Autowired
	RedisUserLoginUtils redisUserLoginUtils;
	@Autowired
	DataDictionaryDao dataDictionaryDao;

	/**
	 * 更新认证信息
	 * 
	 * @author JIANGYOUYAO
	 * @email 935090232@qq.com
	 * @date 2018年9月6日
	 * @param BizAuth
	 * @return
	 */
	@RequestMapping(value = "/modify")
	public @ResponseBody AjaxResult modify(@RequestBody BizAuth bizAuth) {
		bizAuth.setUserId(redisUserLoginUtils.getLoginUser().getOpenId());

		int i = authDao.updateByModel(bizAuth);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "认证信息");
		} else {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL);
		}
	}

	/**
	 * 新增认证信息
	 * @author JIANGYOUYAO
	 * @email 935090232@qq.com
	 * @date 2018年9月12日
	 * @param bizAuth
	 * @return
	 */
	@RequestMapping(value = "/add")
	public @ResponseBody AjaxResult add(@RequestBody BizAuth bizAuth) {
		BizUser user= redisUserLoginUtils.getLoginUser();
		bizAuth.setUserId(user.getOpenId());
		bizAuth.setCreateBy(user.getNickName());
		bizAuth.setUpdateBy(user.getNickName());
		bizAuth.setId(UUIDUtil.getRandomID());
		bizAuth.setAuthStatus(AppConstance.AUTHSTATUS_INDG);
		int i = authDao.insert(bizAuth);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "认证信息");
		} else {
			throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL, "认证信息");
		}
	}

	/**
	 * 查询认证消息
	 * 
	 * @author JIANGYOUYAO
	 * @email 935090232@qq.com
	 * @date 2018年9月6日
	 * @param openId
	 * @return
	 */
	@RequestMapping(value = "/findAuth")
	public @ResponseBody AjaxResult findAuth() {
		BizAuth bizAuth = new BizAuth();
		bizAuth.setUserId(redisUserLoginUtils.getLoginUser().getOpenId());
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, authDao.selectByModel(bizAuth));
		return result;
	}
	public static void main(String[] args) {
		System.out.println((0.1+0.2)==0.3);
		
	}

}